#include "LinkTree.h"
#include<stdio.h>
#include<stdlib.h>
#define true 1
#define false 0

int InitLTree(LTree *tree)
{
    tree->root=NULL;
    return true;
}

struct TreeNode *CreateTreeNode(ElementType element)
{
    struct TreeNode *treeNode=(struct TreeNode *)malloc(sizeof(struct TreeNode));
    if(treeNode==NULL)
    {
        printf("treeNode malloc error!\n");
        return NULL;
    }
    treeNode->data=element;
    treeNode->left=NULL;
    treeNode->right=NULL;
    treeNode->parent=NULL;
}

struct TreeNode *FindBrother(struct TreeNode *treeNode)
{
    if(treeNode->parent==NULL)
    {
        return NULL;
    }
    struct TreeNode *parent=treeNode->parent;
    if(parent->left==treeNode)
    {
        return parent->right;
    }
    else
    {
        return parent->left;
    }
    
}



void InsertNode(struct TreeNode *node,ElementType element)
{
    struct TreeNode *brother=FindBrother(node);
    if(brother!=NULL)
    {
        InsertNode(brother,element);
    }
    if(node->left==NULL)
    {
        node->left=CreateTreeNode(element);
        return;
    }

    if(node->right==NULL)
    {
        node->right=CreateTreeNode(element);
        return;
    } 
    InsertNode(node->left,element);
}

struct TreeNode *FindInsertParent(LTree *tree)
{
    if(tree->root==NULL)
        return NULL;
    if(tree->root->left==NULL)
        return tree->root;
    else if(tree->root->right==NULL)
        return tree->root;
}

void InsertTree(LTree *tree, ElementType element)
{

}

